//
// Copyright (C) 2011 - 2013  Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.2 with QuantLib 1.2.1
//#include "stdafx.h"
#include "ForwardTypePayoff.h"
using namespace Cephei::QL::Instruments;
#include <gen/QL/Payoff.h>
using namespace Cephei::QL;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Instruments::CForwardTypePayoff::CForwardTypePayoff (QL::Position::TypeEnum type, Double strike) : CPayoff(CForwardTypePayoff::typeid)
{
    try
    {
#ifdef HANDLE
        _phForwardTypePayoff = NULL;
#endif
        QuantLib::Position::Type _type = (QuantLib::Position::Type)type ;
        QuantLib::Real _strike = (QuantLib::Real)ValueHelper::Convert (strike); //d
        _ppForwardTypePayoff = new boost::shared_ptr<QuantLib::ForwardTypePayoff> (new QuantLib::ForwardTypePayoff ( _type,  _strike ));
        SetPayoff (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppForwardTypePayoff));
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::CForwardTypePayoff::CForwardTypePayoff (boost::shared_ptr<QuantLib::ForwardTypePayoff>& childNative, Object^ owner) : CPayoff(CForwardTypePayoff::typeid)
{
#ifdef HANDLE
	_phForwardTypePayoff = NULL;
#endif
	_ppForwardTypePayoff = &childNative;
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppForwardTypePayoff));
}
Cephei::QL::Instruments::CForwardTypePayoff::CForwardTypePayoff (QuantLib::ForwardTypePayoff& childNative, Object^ owner) : CPayoff(CForwardTypePayoff::typeid)
{
#ifdef HANDLE
	_phForwardTypePayoff = NULL;
#endif
	_ppForwardTypePayoff = new boost::shared_ptr<QuantLib::ForwardTypePayoff> (&childNative);
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppForwardTypePayoff));
    _ForwardTypePayoffOwner = owner;
    _PayoffOwner = owner;
}

Cephei::QL::Instruments::CForwardTypePayoff::CForwardTypePayoff (CForwardTypePayoff^ copy) : CPayoff(CForwardTypePayoff::typeid)
{
#ifdef HANDLE
	_phForwardTypePayoff = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppForwardTypePayoff = new boost::shared_ptr<QuantLib::ForwardTypePayoff> (copy->GetShared());
        _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppForwardTypePayoff));
    }
}
Cephei::QL::Instruments::CForwardTypePayoff::CForwardTypePayoff (PLATFORM::Type^ t) : CPayoff(CForwardTypePayoff::typeid)
{
#ifdef HANDLE
	_phForwardTypePayoff = NULL;
#endif
	if (!t->IsSubclassOf(CForwardTypePayoff::typeid))
		throw REFNEW Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::CForwardTypePayoff::CForwardTypePayoff (QuantLib::Handle<QuantLib::ForwardTypePayoff>& childNative, Object^ owner)  : CPayoff(CForwardTypePayoff::typeid)
{
	_phForwardTypePayoff = &childNative;
	_ppForwardTypePayoff = &static_cast<boost::shared_ptr<QuantLib::ForwardTypePayoff>>(childNative.currentLink());
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppForwardTypePayoff));
    _ForwardTypePayoffOwner = owner;
}
Cephei::QL::Instruments::CForwardTypePayoff::CForwardTypePayoff (QuantLib::Handle<QuantLib::ForwardTypePayoff> childNative)  : CPayoff(CForwardTypePayoff::typeid)
{
	_phForwardTypePayoff = &childNative;
	_ppForwardTypePayoff = &static_cast<boost::shared_ptr<QuantLib::ForwardTypePayoff>>(childNative.currentLink());
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppForwardTypePayoff));
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::CForwardTypePayoff::CForwardTypePayoff (QuantLib::ForwardTypePayoff childNative)  : CPayoff(CForwardTypePayoff::typeid)
{
#ifdef HANDLE
	_phForwardTypePayoff = NULL;
#endif
	_ppForwardTypePayoff = new boost::shared_ptr<QuantLib::ForwardTypePayoff> (new QuantLib::ForwardTypePayoff (childNative));
    _ppPayoff = new boost::shared_ptr<QuantLib::Payoff> (boost::dynamic_pointer_cast<QuantLib::Payoff> (*_ppForwardTypePayoff));
}
#endif

Cephei::QL::Instruments::CForwardTypePayoff::~CForwardTypePayoff ()
{
    if (_ppForwardTypePayoff != NULL)
    {
	    delete _ppForwardTypePayoff;
        _ppForwardTypePayoff = NULL;
    }
}
Cephei::QL::Instruments::CForwardTypePayoff::!CForwardTypePayoff ()
{
    if (_ppForwardTypePayoff != NULL)
    {
	    delete _ppForwardTypePayoff;
    }
}
QuantLib::ForwardTypePayoff& Cephei::QL::Instruments::CForwardTypePayoff::GetReference ()
{
    if (_ppForwardTypePayoff == NULL) throw REFNEW NativeNullException ();
	return **_ppForwardTypePayoff;
}
boost::shared_ptr<QuantLib::ForwardTypePayoff>& Cephei::QL::Instruments::CForwardTypePayoff::GetShared ()
{
    if (_ppForwardTypePayoff == NULL) throw REFNEW NativeNullException ();
	return *_ppForwardTypePayoff;
}
QuantLib::ForwardTypePayoff* Cephei::QL::Instruments::CForwardTypePayoff::GetPointer ()
{
    if (_ppForwardTypePayoff == NULL) throw REFNEW NativeNullException ();
	return &**_ppForwardTypePayoff;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::ForwardTypePayoff>& Cephei::QL::Instruments::CForwardTypePayoff::GetHandle ()
{
	if (_phForwardTypePayoff == NULL)
	{
		_phForwardTypePayoff = new Handle<QuantLib::ForwardTypePayoff> (*_ppForwardTypePayoff);
	}
	return *_phForwardTypePayoff;
}
#endif
bool Cephei::QL::Instruments::CForwardTypePayoff::HasNative () 
{
	return (_ppForwardTypePayoff != NULL);
}

String^ Cephei::QL::Instruments::CForwardTypePayoff::Description::get ()
{
    try
    {
    	std::string _rv = (std::string)(*_ppForwardTypePayoff)->description ( );   
        String^ _nrv = (String^)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
QL::Position::TypeEnum Cephei::QL::Instruments::CForwardTypePayoff::ForwardType::get ()
{
    try
    {
    	QuantLib::Position::Type _rv = (QuantLib::Position::Type)(*_ppForwardTypePayoff)->forwardType ( );   
        QL::Position::TypeEnum _nrv = (QL::Position::TypeEnum)_rv;
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
String^ Cephei::QL::Instruments::CForwardTypePayoff::Name::get ()
{
    try
    {
    	std::string _rv = (std::string)(*_ppForwardTypePayoff)->name ( );   
        String^ _nrv = (String^)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Double Cephei::QL::Instruments::CForwardTypePayoff::Strike::get ()
{
    try
    {
    	QuantLib::Real _rv = (QuantLib::Real)(*_ppForwardTypePayoff)->strike ( );   
        Double _nrv = (Double)ValueHelper::Convert (_rv); //c
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String(_error.what()));
        else
		    throw REFNEW NativeExcpetion (REFNEW PLATFORM::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Instruments::IForwardTypePayoff^ Cephei::QL::Instruments::CForwardTypePayoff_Factory::Create (QL::Position::TypeEnum type, Double strike)
{
    return REFNEW CForwardTypePayoff ( type,  strike);
}
